/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

import java.io.Serializable;
public class Supplier implements Serializable {
	public Supplier() {
	}
	
	public static Supplier loadSupplierByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadSupplierByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier getSupplierByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getSupplierByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadSupplierByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier getSupplierByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getSupplierByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByORMID(PersistentSession session, int ID) {
		try {
			return (Supplier) session.load(smartgrid.Supplier.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier getSupplierByORMID(PersistentSession session, int ID) {
		try {
			return (Supplier) session.get(smartgrid.Supplier.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (Supplier) session.load(smartgrid.Supplier.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier getSupplierByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (Supplier) session.get(smartgrid.Supplier.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier[] listSupplierByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listSupplierByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier[] listSupplierByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listSupplierByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier[] listSupplierByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.Supplier as Supplier");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Supplier[]) list.toArray(new Supplier[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier[] listSupplierByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.Supplier as Supplier");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Supplier[]) list.toArray(new Supplier[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadSupplierByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadSupplierByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByQuery(PersistentSession session, String condition, String orderBy) {
		Supplier[] suppliers = listSupplierByQuery(session, condition, orderBy);
		if (suppliers != null && suppliers.length > 0)
			return suppliers[0];
		else
			return null;
	}
	
	public static Supplier loadSupplierByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		Supplier[] suppliers = listSupplierByQuery(session, condition, orderBy, lockMode);
		if (suppliers != null && suppliers.length > 0)
			return suppliers[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateSupplierByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateSupplierByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateSupplierByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateSupplierByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateSupplierByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.Supplier as Supplier");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateSupplierByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.Supplier as Supplier");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static Supplier loadSupplierByCriteria(SupplierCriteria supplierCriteria) {
		Supplier[] suppliers = listSupplierByCriteria(supplierCriteria);
		if(suppliers == null || suppliers.length == 0) {
			return null;
		}
		return suppliers[0];
	}
	
	public static Supplier[] listSupplierByCriteria(SupplierCriteria supplierCriteria) {
		return supplierCriteria.listSupplier();
	}
	
	public static Supplier createSupplier() {
		return new smartgrid.Supplier();
	}
	
	public boolean save() {
		try {
			smartgrid.SmartgridPersistentManager.instance().saveObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean delete() {
		try {
			smartgrid.SmartgridPersistentManager.instance().deleteObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean refresh() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().refresh(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean evict() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().evict(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate() {
		try {
			smartgrid.Tariff[] lTariff_Tariff_roles = tariff_Tariff_role.toArray();
			for(int i = 0; i < lTariff_Tariff_roles.length; i++) {
				lTariff_Tariff_roles[i].setSupplier_Tariffs_role(null);
			}
			return delete();
		}
		catch(Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate(org.orm.PersistentSession session) {
		try {
			smartgrid.Tariff[] lTariff_Tariff_roles = tariff_Tariff_role.toArray();
			for(int i = 0; i < lTariff_Tariff_roles.length; i++) {
				lTariff_Tariff_roles[i].setSupplier_Tariffs_role(null);
			}
			try {
				session.delete(this);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			return false;
		}
	}
	
	private java.util.Set this_getSet (int key) {
		if (key == smartgrid.ORMConstants.KEY_SUPPLIER_TARIFF_TARIFF_ROLE) {
			return ORM_tariff_Tariff_role;
		}
		
		return null;
	}
	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {
		public java.util.Set getSet(int key) {
			return this_getSet(key);
		}
		
	};
	
	private int ID;
	
	private String Name;
	
	private String Country;
	
	private java.util.Set ORM_tariff_Tariff_role = new java.util.HashSet();
	
	private void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public int getORMID() {
		return getID();
	}
	
	/**
	 * Nome do fornecedor.
	 */
	public void setName(String value) {
		this.Name = value;
	}
	
	/**
	 * Nome do fornecedor.
	 */
	public String getName() {
		return Name;
	}
	
	/**
	 * Nacionalidade do fornecedor.
	 */
	public void setCountry(String value) {
		this.Country = value;
	}
	
	/**
	 * Nacionalidade do fornecedor.
	 */
	public String getCountry() {
		return Country;
	}
	
	private void setORM_Tariff_Tariff_role(java.util.Set value) {
		this.ORM_tariff_Tariff_role = value;
	}
	
	private java.util.Set getORM_Tariff_Tariff_role() {
		return ORM_tariff_Tariff_role;
	}
	
	public final smartgrid.TariffSetCollection tariff_Tariff_role = new smartgrid.TariffSetCollection(this, _ormAdapter, smartgrid.ORMConstants.KEY_SUPPLIER_TARIFF_TARIFF_ROLE, smartgrid.ORMConstants.KEY_TARIFF_SUPPLIER_TARIFFS_ROLE, smartgrid.ORMConstants.KEY_MUL_ONE_TO_MANY);
	
	/**
	 * Retorna o objecto serializado no formato JSon.
	 */
	public String getJSon() {
		//TODO: Implement Method
		throw new UnsupportedOperationException();
	}
	
	public String toString() {
		return String.valueOf(getID());
	}
	
}
